package com.sdb.demo_3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ListView nameListView;
    private String[] nameArr = {"张三","李四","王五","赵柳","董卓"};
    private ArrayList<Student> studentArrayAdapter = new ArrayList<>();
    private MyAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initStuList();
        
        nameListView = findViewById(R.id.name_listView);
        adapter = new MyAdapter(MainActivity.this, studentArrayAdapter);
        nameListView.setAdapter(adapter);
    }

    private void initStuList() {
        Student s1 = new Student(R.drawable.dog1, "张三", 18);
        Student s2 = new Student(R.drawable.dog2, "赵四", 19);
        Student s3 = new Student(R.drawable.dog3, "王五", 20);
        Student s4 = new Student(R.drawable.dog4, "赵柳", 21);
        Student s5 = new Student(R.drawable.dog5, "董卓", 22);
        studentArrayAdapter.add(s1);
        studentArrayAdapter.add(s2);
        studentArrayAdapter.add(s3);
        studentArrayAdapter.add(s4);
        studentArrayAdapter.add(s5);
    }
}
